package net.qunzhi.modules.cms.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import net.qunzhi.common.utils.Constant;
import net.qunzhi.modules.cms.dao.SpiderDao;
import net.qunzhi.modules.cms.dao.TbFlowStateDao;
import net.qunzhi.modules.cms.entity.TbElectricityStateEntity;
import net.qunzhi.modules.cms.entity.TbEquipmentEntity;
import net.qunzhi.modules.cms.entity.TbFlowStateEntity;
import net.qunzhi.modules.cms.entity.TbPressureStateEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

@Component
public class SpiderService {

    @Autowired
    private TbPressureStateService tbPressureStateService;
    @Autowired
    private TbFlowStateService tbFlowStateService;
    @Autowired
    private SpiderDao spiderDao;
    private static SpiderService spiderService;

    @Autowired
    private TbEquipmentService equipmentService;
    @Autowired
    private TbElectricityStateService electricityStateService;
    @PostConstruct //通过@PostConstruct实现初始化bean之前进行的操作
    public void init() {
        // 初使化时将已静态化的testService实例化
        spiderService = this;
        spiderService.tbPressureStateService = this.tbPressureStateService;
        spiderService.tbFlowStateService = this.tbFlowStateService;
        spiderService.tbFlowStateService = this.tbFlowStateService;
        spiderService.spiderDao = this.spiderDao;
        spiderService.equipmentService = this.equipmentService;
        spiderService.electricityStateService = this.electricityStateService;
    }


    public void insertPressureState(ArrayList<TbPressureStateEntity> list) {
        spiderService.tbPressureStateService.saveBatch(list);
    }

    public void insertFlowState(ArrayList<TbFlowStateEntity> list) {
        spiderService.tbFlowStateService.saveBatch(list);
    }

    /**
     * 获取使用中的调度电力设备列表
     */
    public List<TbEquipmentEntity> getEquipmentList() {
        return spiderService.equipmentService
                .list(new QueryWrapper<TbEquipmentEntity>()
                        .eq("is_used", Constant.ONE)
                );
    }

    public void insertElectricityState(ArrayList<TbElectricityStateEntity> list) {
        spiderService.electricityStateService.saveBatch(list);
    }
}
